function hiddenlogbyid( ids ) 
{
   var div = document.getElementById( ids );
   if ( div == null || div == undefined ) return;
   if ( div.style.display == "" )
      div.style.display = 'none';
   else
      div.style.display = "";
}

function isidshidden( ids )
{
   var div = document.getElementById( ids );
   if ( div == null || div.style.display == "none" )
      return true;
   else
      return false;
}

function hididallways( ids )
{
    if ( !isidshidden( ids ) )
         hiddenlogbyid( ids );
}

function hd258()
{
    var ids = new Array( 
         "diva",
         "dive",
         "divc",
         "divx",
         "divp",
         "divf",
         "divb"
    );

    for ( var i=0; i<ids.length; i++ )
       hididallways( ids[i] );

}

function repaintbottom258()
{
        var sz = getQueryString("p");
        if (sz != null && sz == "258" )
        {
//            g_col = parseInt(sz);
//            g_row = g_col + 2;

            var halfblank = parseInt(parseInt(g_col/2)/2);
            var halfw = parseInt(g_col/2) - halfblank;

            var idx = 0;
            for ( var i=0; i<halfblank; i++ )
            {    deleteChess(g_row -1, idx, false); // chesspos += '0';
//                 deleteChess(g_row/2 -1, idx, false); // chesspos += '0';
                 idx++;
            }
            for ( i=0; i<halfw /*-2*/; i++ )
            {
    if (matrix[g_row -1][idx] == null)
    {            matrix[g_row -1][idx] = createChessOne(g_row -1, idx, 'z'); // chesspos += 'z';
//                 matrix[g_row/2 -1][idx] = createChessOne(g_row/2 -1, idx, 'z'); // chesspos += 'z';
    }
                idx ++;
            }

            if ( parseInt(g_col/2) != g_col/2 )
            {    deleteChess(g_row -1, idx, false); // chesspos += '0';
//                 deleteChess(g_row/2 -1, idx, false); // chesspos += '0';
                 idx ++;
            }

            for ( i=0; i<halfw /*-2*/; i++ )
            {
    if (matrix[g_row -1][idx] == null)
    {            matrix[g_row -1][idx] = createChessOne(g_row -1, idx, 'Z'); // chesspos += 'z';
//                 matrix[g_row/2 -1][idx] = createChessOne(g_row/2 -1, idx, 'Z'); // chesspos += 'z';
    }            idx ++;
            }
            for ( i=0; i<halfblank; i++ )
            {    deleteChess(g_row -1, idx, false); // chesspos += '0';
//                 deleteChess(g_row/2 -1, idx, false); // chesspos += '0';
                 idx++;
            }

            return;
        } 

}

function afterMoveChessTo258( pos, clr )
{
    syncMid258( prepos, clr );
    syncMid258( pos, clr );
}

function inMidTop258( pos )
{
    var top = new Array( 
         1,1, 3,1, 5,1,
         1,3,       5,3,
         1,5, 3,5, 5,5
    );
    for ( var i=0; i<top.length; i+=2 )
        if ( pos.c == top[i] &&
             pos.r == top[i+1] ) return true;
    return false;
}

function inMidBottom258( pos )
{
    var top = new Array( 
         1,8,   3,8,   5,8,
         1,10,         5,10,
         1,12, 3,12, 5,12
    );
    for ( var i=0; i<top.length; i+=2 )
        if ( pos.c == top[i] &&
             pos.r == top[i+1] ) return true;
    return false;
}

function inMid258( pos )
{
    return inMidTop258( pos ) ||
           inMidBottom258( pos );
}

function mirrleMid258( pos, bottom, clr )
{
            if ( matrix[pos.r][pos.c] != null )
            {   // create the bottom.
                clr = matrix[pos.r][pos.c].color;
                if ( matrix[bottom.r][bottom.c] == null )
                    // create.
                    matrix[bottom.r][bottom.c] = createChessOne( bottom.r, bottom.c, clr=='r'?'z':'Z' );
            } else {
                // delete the bottom.
                if ( matrix[bottom.r][bottom.c] != null )
                    deleteChess( bottom.r, bottom.c, false );
            }            
}

function syncMid258( pos, clr )
{
    if ( inMid258( pos ) )
    {
        if ( inMidTop258( pos ) )
        {    // top.
            var bottom = { r:pos.r+7, c:pos.c };
/*
            if ( matrix[pos.r][pos.c] != null )
            {   // create the bottom.
                if ( matrix[bottom.r][bottom.c] == null )
                    // create.
                    matrix[bottom.r][bottom.c] = createChessOne( bottom.r, bottom.c, clr=='r'?'z':'Z' );
            } else {
                // delete the bottom.
                if ( matrix[bottom.r][bottom.c] != null )
                    deleteChess( bottom.r, bottom.c, false );
            }            
*/          mirrleMid258( pos, bottom, clr );
        } else {
             // bottom.
            var top = { r:pos.r-7, c:pos.c };
            mirrleMid258( pos, top, clr );
        }
    }
}